package com.wanmait.gohome.controller.manage;

import com.github.pagehelper.PageInfo;
import com.wanmait.gohome.pojo.Mark;
import com.wanmait.gohome.pojo.Task;
import com.wanmait.gohome.pojo.Userinfo;
import com.wanmait.gohome.service.MarkService;
import com.wanmait.gohome.service.TaskService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/manage/task")
public class ManageTaskController {
    @Resource
    private TaskService taskService;
    @Resource
    private MarkService markService;
    @RequestMapping("show")
    public void list(){}
    @PostMapping("list")
    @ResponseBody
    public ModelAndView show(){
        ModelAndView mv = new ModelAndView();
        PageInfo<Task> taskPageInfo = taskService.selectAllTask();
        List<Mark> markList = markService.selectAll();
        mv.addObject("marks",markList);
        mv.addObject("task",taskPageInfo);
        mv.addObject("count",taskService.getTaskCount());
        mv.addObject("finishCount",taskService.getFinishCount());
        mv.setViewName("manage/ajaxJsp/taskShow");
        return mv;
    }
    //查出任务审核
    @PostMapping("ajaxJsp/taskPass")
    @ResponseBody
    public ModelAndView taskPass(){
        ModelAndView mv = new ModelAndView();
        PageInfo<Task> taskPass = taskService.passTask();
        mv.addObject("taskPass",taskPass);
        mv.addObject("count",taskService.getTaskCount());
        mv.setViewName("manage/ajaxJsp/taskPass");
        return mv;
    }
    //查出完成
    @PostMapping("ajaxJsp/finishPass")
    @ResponseBody
    public ModelAndView finishPass(){
        ModelAndView mv = new ModelAndView();
        PageInfo<Task> finishTask = taskService.finishTask();
        mv.addObject("finishTask",finishTask);
        mv.setViewName("manage/ajaxJsp/finishPass");
        return mv;
    }
//根据状态查出任务
    @PostMapping("ajaxJsp/listByMark")
    @ResponseBody
    public ModelAndView ListByMark(Integer id){
        PageInfo<Task> pageInfo = taskService.selectTaskByMarkId(id);
        List<Mark> marks = markService.selectAll();
        ModelAndView mv = new ModelAndView();
        mv.addObject("markTask",pageInfo);
        mv.addObject("marks",marks);
        mv.setViewName("manage/ajaxJsp/listByMark");
        return mv;
    }
    @RequestMapping("/closure")//拒绝
    @ResponseBody
    public void closure(Integer id)
    {
        taskService.updateRefuse(id);
    }
    @RequestMapping("deblocking")//同意
    @ResponseBody
    public void deblocking(Integer id)
    {
        taskService.updatePass(id);
    }



    @RequestMapping("/Finshclosure")//拒绝
    @ResponseBody
    public void Finshclosure(Integer id)
    {
        taskService.updateFinishRefuse(id);
    }
    @RequestMapping("Finshdeblocking")//同意
    @ResponseBody
    public void Finshdeblocking(Integer id)
    {
        System.out.println(id);
        taskService.updateFinish(id);
    }

    @PostMapping("Reason")
    @ResponseBody()
    public void reject(Task task){
        taskService.insertReject(task);
    }
}
